﻿using UFIDA.U9.CBO.FI.Enums;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForARtonull : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //应收单
            UFIDA.U9.AR.ARBill.ARBillHead ar = key.GetEntity() as UFIDA.U9.AR.ARBill.ARBillHead;
            if (ar == null) return;

            #region 复制清空应收单:单据状态,审批意见
            //清空审批意见
            if(ar.OriginalData.DocStatus == BillStatusEnum.Approved && ar.DocStatus== BillStatusEnum.Opened) {
                if (ar.DescFlexField.PrivateDescSeg3 != "" || ar.DescFlexField.PrivateDescSeg3 != null)
                {
                    ar.DescFlexField.PrivateDescSeg3 = "";
                }
                //清空附件
                if (ar.DescFlexField.PrivateDescSeg11 != "" || ar.DescFlexField.PrivateDescSeg11 != null)
                {
                    ar.DescFlexField.PrivateDescSeg11 = "";
                }
                //清空oa标识
                if (ar.DescFlexField.PubDescSeg6 != "" || ar.DescFlexField.PubDescSeg6 != null)
                {
                    ar.DescFlexField.PubDescSeg6 = "";
                }
            }
            if (ar.DocStatus ==BillStatusEnum.Opened)
            {
                if (ar.DescFlexField.PrivateDescSeg3 != "" || ar.DescFlexField.PrivateDescSeg3 != null)
                {
                    ar.DescFlexField.PrivateDescSeg3 = "";
                }
                //清空附件
                if (ar.DescFlexField.PrivateDescSeg11 != "" || ar.DescFlexField.PrivateDescSeg11 != null)
                {
                    ar.DescFlexField.PrivateDescSeg11 = "";
                }
                //清空oa标识
                if (ar.DescFlexField.PubDescSeg6 != "" || ar.DescFlexField.PubDescSeg6 != null)
                {
                    ar.DescFlexField.PubDescSeg6 = "";
                }
            }
            //单据标识
            if (ar.OriginalData.DocStatus == BillStatusEnum.Opened && ar.DocStatus == BillStatusEnum.Approving)
            {
                int n = 1;
                if (ar.DescFlexField.PubDescSeg8 == "")
                {

                    ar.DescFlexField.PubDescSeg8 = n.ToString();
                }
                else
                {
                    ar.DescFlexField.PubDescSeg8 = (decimal.Parse(ar.DescFlexField.PubDescSeg8) + n).ToString();
                }
            }



            #endregion

        }

    }
}
